Sunday, February 12, 2012

Bind and socket [ networks lab ]


Bind 


#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<unistd.h>
#include<netinet/in.h>
int main()
{
 int sockd1,s;
 struct sockaddr_in p;
 sockd1=socket(AF_INET,SOCK_STREAM,0);
 if(sockd1==-1)
  {
   printf("Sockect wasn't created\n");
  }
 else
  {
   printf("socket was perfectly created with value %d\n",sockd1);
   s=bind(sockd1,(struct sockaddr*) &p,sizeof(struct sockaddr));
   if(s==-1)
   printf("bind wasn't done\n");
   else
   printf("bind was done\n");
  }
 close(sockd1);
 return(0);

No comments:

Post a Comment