Linux API/network2019. 5. 16. 18:48

 

 

[링크 : http://www.linuxhowtos.org/C_C++/socket.htm] c

[링크 : https://linux.m2osw.com/c-implementation-udp-clientserver] cpp

 

 

[링크 : ]

'Linux API > network' 카테고리의 다른 글

리눅스 UDP 소켓  (0) 2019.05.24
리눅스 TCP 소켓  (0) 2019.05.24
linux socket 관련  (0) 2015.01.22
멀티캐스트 되는지 여부 확인  (0) 2014.11.21
net tools 소스코드  (0) 2011.11.07
Posted by 구차니
Linux API/network2015. 1. 22. 19:49


TCP Connection

UDP Connectionless


그래서 UDP는

socket()

bind()

recvfrom()

sendto()

close()

----

socket()

gethostbyname()

sento()

recvfrom()

close()

로 진행되고


TCP는

socket()

bind()

listen()

accept()

select()

recv()

send()

close()

----

socket()

gethostbyname()

connect()

sen()

recv()

close()

로 진행된다.


[링크 : http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzab6/connectionor.htm] TCP

[링크 : http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzab6/connectionless.htm] UDP


소켓은

32K 정도는 열수 있을 듯.

[링크 : http://stackoverflow.com/questions/3430474/max-number-of-socket-on-linux]


recvfrom

[링크 : http://forum.falinux.com/zbxe/index.php?document_srl=441147&mid=C_LIB]


'Linux API > network' 카테고리의 다른 글

리눅스 TCP 소켓  (0) 2019.05.24
linux udp cpp example  (0) 2019.05.16
멀티캐스트 되는지 여부 확인  (0) 2014.11.21
net tools 소스코드  (0) 2011.11.07
INADDR_ANY/INADDR_BROADCAST/INADDR_NONE 매크로  (0) 2011.09.29
Posted by 구차니
Linux API/network2014. 11. 21. 09:21
윈도우에서는 서버관련 유틸로 msdn에 제공하는 것 같고..
리눅스는 우분투 에서 확인해보니.. 해당 프로그램이 존재하지 않는다 -_-
(버전이 낮아서 그런걸지도..)

omping 은 레드햇용인가...?
아무튼 커널설정에서 보는것 외에는
설정하고 나서 핑 날려 보는 게 전부인가.. -_ㅠ

[링크 : http://www.cisco.com/en/US/docs/ios/ipmulti/configuration/guide/imc_verify_op.html]
[링크 : http://technet.microsoft.com/en-us/library/cc787891(v=ws.10).aspx]
[링크 : http://www-01.ibm.com/.../SSPHQG_7.1.0/com.ibm.powerha.trgd/ha_trgd_test_multicast.htm
[링크 : http://serverfault.com/questions/137976/how-do-i-know-if-ip-multicasting-is-enabled-on-my-network]
[링크 : http://linux.die.net/man/8/omping ]

'Linux API > network' 카테고리의 다른 글

linux udp cpp example  (0) 2019.05.16
linux socket 관련  (0) 2015.01.22
net tools 소스코드  (0) 2011.11.07
INADDR_ANY/INADDR_BROADCAST/INADDR_NONE 매크로  (0) 2011.09.29
hton(), ntoh()  (0) 2011.09.26
Posted by 구차니
Linux API/network2011. 11. 7. 23:30
아따 여러단계로 해놨네 -_-
route 라던가 ifconfig 등의 소스를 받을수 있는 링크이다.
binutils에 속해있을 줄 알았는데 별도의 소스일줄이야...

[링크 : http://net-tools.berlios.de/]
[링크 : http://net-tools.sourceforge.net/]
[링크 : http://sourceforge.net/projects/net-tools/]

'Linux API > network' 카테고리의 다른 글

linux socket 관련  (0) 2015.01.22
멀티캐스트 되는지 여부 확인  (0) 2014.11.21
INADDR_ANY/INADDR_BROADCAST/INADDR_NONE 매크로  (0) 2011.09.29
hton(), ntoh()  (0) 2011.09.26
netstat 에서 0.0.0.0의 의미  (2) 2009.12.07
Posted by 구차니
Linux API/network2011. 9. 29. 18:05
/usr/include/netinet/in.h

176 /* Address to accept any incoming messages.  */
177 #define INADDR_ANY      ((in_addr_t) 0x00000000)
178 /* Address to send to all hosts.  */
179 #define INADDR_BROADCAST    ((in_addr_t) 0xffffffff)
180 /* Address indicating an error return.  */
181 #define INADDR_NONE     ((in_addr_t) 0xffffffff) 

hton() 과 같은 변환없이 사용해도 되는 매크로인데
255.255.255.255(BROADCAST/NONE) 혹은 0.0.0.0(ANY) 으로 치환이 된다.

'Linux API > network' 카테고리의 다른 글

멀티캐스트 되는지 여부 확인  (0) 2014.11.21
net tools 소스코드  (0) 2011.11.07
hton(), ntoh()  (0) 2011.09.26
netstat 에서 0.0.0.0의 의미  (2) 2009.12.07
ioctl을 이용한 정보수집  (0) 2009.11.30
Posted by 구차니
Linux API/network2011. 9. 26. 15:38
프로그래밍을 하다보면 짜증나는 것 중에 하나가 바로 이넘의 Byte Order이다.
Intel CPU가 Little Endian 이다 보니 Big Endian 과 유사한 비트 스트림의 경우에는
순서를 죄다 뒤집어주어야 한다. (어셈블러로 그냥 이런 명령어 하나 좀 만들어 주지 -_-)

uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);

The htonl() function converts the unsigned integer hostlong from host byte order to network byte order.
The htons() function converts the unsigned short integer hostshort from host byte order to network byte order.

The ntohl() function converts the unsigned integer netlong from network byte order to host byte order.
The ntohs() function converts the unsigned short integer netshort from network byte order to host byte order.

On the i80x86 the host byte order is Least Significant Byte first, whereas the network byte order, as used on the Internet, is Most Significant Byte first.
 
[링크 : http://linux.die.net/man/3/htonl

머.. 정리 하자면
hton 은 ip 주소를 보낼때
ntoh 는 ip 주소를 받았을때 사용하면 될듯? 
Posted by 구차니
Linux API/network2009. 12. 7. 13:42
0.0.0.0 은 간단하게 all allow의 의미라고 한다.







MS 넘들은 뻑하면 "의도된 설계입니다"
이 한마디로 구렁이 담 넘어 가듯 넘어간단 말이야 ㄱ-

The Winsock application that is listening on the designated port was written so that it binds to any local IP address by using INADDR_ANY. This means that the application will listen to all local interfaces and you can connect to the port of any of them. This is why netstat -an shows IP address 0.0.0.0 listening on the port.

[링크 : http://support.microsoft.com/?scid=kb%3Ben-us%3B175952&x=6&y=11]



-------------
$ netstat -an | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:2049                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:674                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:139                 0.0.0.0:*                   LISTEN

$ netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 *:nfs                       *:*                         LISTEN
tcp        0      0 *:acap                      *:*                         LISTEN
tcp        0      0 *:netbios-ssn               *:*                         LISTEN

리눅스 상에서는 0.0.0.0 은 *로 표시 되기도 한다.
(-n 옵션은 numeric하게 출력할지 아니면 /etc/services 의 문자열로 출력할지를 결정하는 옵션이다)

'Linux API > network' 카테고리의 다른 글

INADDR_ANY/INADDR_BROADCAST/INADDR_NONE 매크로  (0) 2011.09.29
hton(), ntoh()  (0) 2011.09.26
ioctl을 이용한 정보수집  (0) 2009.11.30
termios 구조체를 이용한 자국반향(echo) 제어  (0) 2009.08.27
canonical / non-canonical  (0) 2009.08.27
Posted by 구차니
Linux API/network2009. 11. 30. 17:35
ioctl은

#include <sys/ioctl.h>
int ioctl(int d, int request, ...);

이런 모양인데, int d는 descriptor로 socket을 통해 받아와야 한다.
그리고 request는 /usr/include/bits/ioctls.h 파일에 정의된 내용을 사용하면 된다.


잠시 socket을 소개하자면

#include <sys/socket.h>
int socket(int domain, int type, int protocol);

domain
    Name                Purpose                          Man page
    PF_UNIX, PF_LOCAL   Local communication              unix(7)
    PF_INET             IPv4 Internet protocols          ip(7)
    PF_INET6            IPv6 Internet protocols
    PF_IPX              IPX - Novell protocols
    PF_NETLINK          Kernel user interface device     netlink(7)
    PF_X25              ITU-T X.25 / ISO-8208 protocol   x25(7)
    PF_AX25             Amateur radio AX.25 protocol
    PF_ATMPVC           Access to raw ATM PVCs
    PF_APPLETALK        Appletalk                        ddp(7)
    PF_PACKET           Low level packet interface       packet(7)

type
   SOCK_STREAM
          Provides sequenced, reliable, two-way, connection-based byte streams.  An  out-of-band  data  transmission
          mechanism may be supported.

   SOCK_DGRAM
          Supports datagrams (connectionless, unreliable messages of a fixed maximum length).

   SOCK_SEQPACKET(is not implemented for AF_INET)
          Provides  a  sequenced,  reliable,  two-way connection-based data transmission path for datagrams of fixed
          maximum length; a consumer is required to read an entire packet with each read system call.

   SOCK_RAW
          Provides raw network protocol access.

   SOCK_RDM
          Provides a reliable datagram layer that does not guarantee ordering.

   SOCK_PACKET
          Obsolete and should not be used in new programs; see packet(7).


protocol
    Normally only a single protocol exists to support a particular socket type within a given protocol family, in which case protocol can be specified as 0.

값들을 필요로 한다.

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/article/network_information#s-2.2]

'Linux API > network' 카테고리의 다른 글

hton(), ntoh()  (0) 2011.09.26
netstat 에서 0.0.0.0의 의미  (2) 2009.12.07
termios 구조체를 이용한 자국반향(echo) 제어  (0) 2009.08.27
canonical / non-canonical  (0) 2009.08.27
struct in_addr  (0) 2009.08.18
Posted by 구차니
Linux API/network2009. 8. 27. 14:47
Try It Out − A Password Program with termios

1. Our password program, password.c, begins with the following definitions:
#include <termios.h>
#include <stdio.h>
#define PASSWORD_LEN 8
int main()
{
    struct termios initialrsettings, newrsettings;
    char password[PASSWORD_LEN + 1];

2. Next, add in a line to get the current settings from the standard input and copy them into the termios
structure that we created above.
    tcgetattr(fileno(stdin), &initialrsettings);

3. Make a copy of the original settings to replace them at the end. Turn off the ECHO flag on the
newrsettings and ask the user for their password:
    newrsettings = initialrsettings;
    newrsettings.c_lflag &= ~ECHO;
    printf("Enter password: ");

4. Next, set the terminal attributes to newrsettings and read in the password. Lastly, reset the terminal
attributes to their original setting and print the password to render all the previous effort useless.
    if(tcsetattr(fileno(stdin), TCSAFLUSH, &newrsettings) != 0) {
        fprintf(stderr,"Could not set attributes\n");
    }
    else {
        fgets(password, PASSWORD_LEN, stdin);
        tcsetattr(fileno(stdin), TCSANOW, &initialrsettings);
        fprintf(stdout, "\nYou entered %s\n", password);
    }
    exit(0);
}

[링크 : http://people.freedesktop.org/~nagappan/beginning-linux-programming.pdf]

[링크 : http://ttongfly.net/zbxe/?document_srl=45222]
ttongfly.net 의 내용은 아마도 위의 beginning linux programming의 내용을 번역한 것으로 보인다.

위와 같은 작동은 간단하게 쉘에서
"stty -echo" << echo 끔
"stty echo" << echo 켬
로 가능하다.

하지만, 프로그램에서 쉘 호출 해봤자, 자기 자신에게 적용이 안되므로
termios를 이용해서 직접 제어를 해야 하는데, termios는 말그대로 TERMinal IO Stucture 이다.
소스에서 include 할녀석은 <termios.h> 이고 이녀석은 <bits/termios.h> 을 물어온다.

$ cat /usr/include/bits/termios.h
...
struct termios
  {
    tcflag_t c_iflag;           /* input mode flags */
    tcflag_t c_oflag;           /* output mode flags */
    tcflag_t c_cflag;           /* control mode flags */
    tcflag_t c_lflag;           /* local mode flags */
    cc_t c_line;                        /* line discipline */
    cc_t c_cc[NCCS];            /* control characters */
    speed_t c_ispeed;           /* input speed */
    speed_t c_ospeed;           /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
  };
...
/* c_lflag bits */
#define ISIG    0000001
#define ICANON  0000002
#if defined __USE_MISC || defined __USE_XOPEN
    # define XCASE  0000004
#endif
#define ECHO    0000010
#define ECHOE   0000020
#define ECHOK   0000040
#define ECHONL  0000100
#define NOFLSH  0000200
#define TOSTOP  0000400
#ifdef __USE_MISC
    # define ECHOCTL 0001000
    # define ECHOPRT 0002000
    # define ECHOKE  0004000
    # define FLUSHO  0010000
    # define PENDIN  0040000
#endif
#define IEXTEN  0100000

'Linux API > network' 카테고리의 다른 글

netstat 에서 0.0.0.0의 의미  (2) 2009.12.07
ioctl을 이용한 정보수집  (0) 2009.11.30
canonical / non-canonical  (0) 2009.08.27
struct in_addr  (0) 2009.08.18
ifup/ifdown  (0) 2009.08.18
Posted by 구차니
Linux API/network2009. 8. 27. 14:24
리눅스 터미널 프로그래밍에서
캐노니컬 모드(canonical)는 한줄 단위로 받아들이고
넌 캐노니컬 모드(non-canonical)는 문자 단위로 받아들인다.

[링크 : http://ttongfly.net/zbxe/?document_srl=45222]
Posted by 구차니