<< Prev | Beej's Guide to Network Programming (cloned from beej.us) | Next >> |
Hosted at Teoria dei Segnali.it - Blog - Download - Signal Transmission - Internet Application Layer - Wiki - Newsletter |
Structures for handling internet addresses
#include <netinet/in.h> struct sockaddr_in { short sin_family; // e.g. AF_INET unsigned short sin_port; // e.g. htons(3490) struct in_addr sin_addr; // see struct in_addr, below char sin_zero[8]; // zero this if you want to }; struct in_addr { unsigned long s_addr; // load with inet_aton() };
These are the
basic structures for all syscalls and functions that deal with internet
addresses. In memory, the
Just kidding on that end-of-the-universe thing...if the universe does
end when you cast a
So, with that in mind, remember that whenever a function says it
takes a
There's also this
Now, that
With IPv4 (what basically everyone in 2005 still uses), the
struct sockaddr_in myaddr; int s; myaddr.sin_family = AF_INET; myaddr.sin_port = htons(3490); inet_aton("63.161.169.137", &myaddr.sin_addr.s_addr); s = socket(PF_INET, SOCK_STREAM, 0); bind(s, (struct sockaddr*)myaddr, sizeof(myaddr));
accept(), bind(), connect(), inet_aton(), inet_ntoa()
<< Prev | Beej's Guide to Network Programming (cloned from beej.us) | Next >> |