why is the bind command always return -1 in this program
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <netinet/in.h> #include <sys/socket.h> #include <sys/types.h> int main(void) { int sv; /* Socket. */ struct sockaddr_in info; int sinfo; const unsigned char ipnum[] = { 123, 2, 3, 4 }; if((sv = socket(AF_INET, SOCK_STREAM, 0)) == -1) { fprintf(stderr, "Couldn't make sockets.\n"); return -1; } memset(&info, 0, sizeof info); info.sin_family = AF_INET; info.sin_port = htons(9000); memcpy(&info.sin_addr.s_addr, &ipnum, 4); sinfo = sizeof info; if((bind(sv, (struct sockaddr *)&info, sinfo)) == -1) { fprintf(stderr, "Couldn't bind ipv4 to socket.\n"); close(sv); return -1; } system("netstat --unix -p | grep \"test\""); close(sv); return 0; }



LinkBack URL
About LinkBacks


