BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡

±Û¾´ÀÌ: bind bind Å×½ºÆ® Á¶È¸¼ö: 10928


#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#define MSG "Test Message"

int main() {
int sd1, sd2 ; /* ¼ÒÄϹøÈ£ */
struct sockaddr_in ServerAddr, ClientAddr ; /* ¼ÒÄÏÁÖ¼Ò ±¸Á¶Ã¼ */
u_short rtn1, rtn2; /* Æ÷Æ®¹øÈ£ */
int addr_len ;

/* ¼ÒÄÏÁÖ¼Ò ±¸Á¶Ã¼ ÃʱâÈ­ */
ServerAddr.sin_family = ClientAddr.sin_family = PF_INET ;
ServerAddr.sin_addr.s_addr = ClientAddr.sin_addr.s_addr = htonl(INADDR_ANY) ;
ServerAddr.sin_port = htons(7);
ClientAddr.sin_port = htons(0) ; /* ½Ã½ºÅÛÀÌ Æ÷Æ®¹øÈ£ ¹èÁ¤ */

sd1=socket(AF_INET, SOCK_STREAM, 0);
sd2=socket(AF_INET, SOCK_DGRAM, 0);

addr_len=sizeof(ClientAddr);
if(bind(sd1, (struct sockaddr*)&ClientAddr, addr_len)) printf("bind error!\n");
if(connect(sd1, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr))<0) {
printf("Error : Connect failed!!!\n") ;
exit(1) ;
}
getsockname(sd1, (struct sockaddr*)&ClientAddr, &addr_len) ;
rtn1 = ClientAddr.sin_port ;

sendto(sd2, MSG, strlen(MSG), 0, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr)) ;
getsockname(sd2, (struct sockaddr*)&ClientAddr, &addr_len) ;
rtn2 = ClientAddr.sin_port ;

printf("stream socket's bind return = %d\n", rtn1 ) ;
printf("datagram socket's bind return = %d\n", rtn2) ;

close(sd1) ;
close(sd2) ;
}

°ü·Ã±Û : 1 °Ç ±Û¾´½Ã°£ : 2002/11/14 17:02 from 218.154.16.35

 

Á¦ ¸ñ

Á¶È¸

³¯Â¥

±Û¾´ÀÌ

bind Å×½ºÆ®

10928

2002.01.19

bind


  nbtstat ¸¦ À¯´Ð½º¿¡¼­ ¸ñ·Ïº¸±â »õ±Û ¾²±â Áö¿ì±â ÀÀ´ä±Û ¾²±â ±Û ¼öÁ¤ ½Ã½ºÅÛÄÝ»ç¿ë¿¬½À  
BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡