Skip to content

Instantly share code, notes, and snippets.

@fatih
Created July 13, 2012 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatih/3105167 to your computer and use it in GitHub Desktop.
Save fatih/3105167 to your computer and use it in GitHub Desktop.
Sockaddr casting example
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
int main(void)
{
struct sockaddr_in *server;
server->sin_family = AF_INET;
struct sockaddr *sa = (struct sockaddr *)server;
if(sa->sa_family == AF_INET)
printf("AF_INET\n");
else
printf("AF_UNSPEC\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment