The “correct” way for IPv4 without magic +2:
struct sockaddr_in* addr = (struct sockaddr_in*)&ifr.ifr_addr;
inet_pton(AF_INET, "10.12.0.1", &addr->sin_addr);
To use IPv6, cast it to sockaddr_in6
More Related Contents:
- What is the octet mode in TFTP?
- C – list all files in current directory then move in directory above, list files, and so on until root directory is reached [closed]
- Hide password input on terminal
- Can I share a file descriptor to another process on linux or are they local to the process?
- Pass arguments into C program from command line
- Segmentation fault handling
- Is there an alternative sleep function in C to milliseconds?
- How to compile .c file with OpenSSL includes?
- How to print the address of a function?
- Clearing output of a terminal program Linux C/C++
- How to use printf to display off_t, nlink_t, size_t and other special types?
- `bash: ./a.out: No such file or directory` on running executable produced by `ld`
- Linking against older symbol version in a .so file
- What is the difference between using _exit() & exit() in a conventional Linux fork-exec?
- How can you flush a write using a file descriptor?
- How to trap unaligned memory access?
- Why getch() returns before press any key?
- Does linux allow any system call to be made from signal handlers?
- How can I get the keyboard state in Linux?
- Problem usage memory in C
- What are trade offs for “busy wait” vs “sleep”?
- Implicit declaration of ‘gets’
- Implementing pipe in C
- Pipe two or more shell commands in C using a loop
- What can cause a “Resource temporarily unavailable” on sock send() command
- Returning struct containing array
- C: Different implementation of clock() in Windows and other OS?
- How to read terminal’s input buffer immediately after keypress
- What is ‘:-!!’ in C?
- Where can I find system call source code?