
| TCP | UDP |
|---|---|
| 연결지향형 | 비연결형 |
| 신뢰성 보장 | 신뢰성을 보장 X |
| 흐름 제어 기능 O | 흐름 제어 기능 X |
| 순서 보장 | 순서를 보장 X |
| 서비스 | 포트 번호 |
|---|---|
| Telent | 23 |
| FTP | 21 |
| HTTP | 80 |

#include <netdb.h>
struct hostnet *gethostent(void);
void sethostent(int stayopen);
void edhostent(void);
stayopen: IP 주소 데이터베이스를 열어둘 것인지 여부를 나타내는 값
gethostent: 호스트명과 IP 주소를 읽어서 hostent 구조체에 저장하고 해당 주소를 리턴
sethostent: 데이터베이스의 현재 읽기 위치를 시작 부분으로 재설정
endhostent: 데이터 베이스를 닫음
struct hostent{
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
: 호스트명을 인자로 받아 데이터베이스에서 해당 항목을 검색해 hostent 구조체에 저장하고 그 주소를 리턴
#include <netdb.h>
struct hostent *gethostbyname(const char *name);
name: 검색하려는 호스트명
: IP주소를 인자로 받아 데이베이스에서 해당 항목을 검색해 hostent 구조체에 저장하고 그 주소를 리턴
#include <netdb.h>
#include <sys/socket.h>
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type);
addr: 검색하려는 IP주소
len: addr 길이
type: IP주소 형식
#include <netdb.h>
struct servent *getservent(void);
void setservent(inst stayopen);
void endservent(void);
stayopen: 포트 정보 데이터베이스를 열어둘 것인지 여부를 나타내는 값
getservent: 포트 정보를 읽어서 servent 구조체에 저장하고 그 주소를 리턴
setservent: 데이터베이스의 현재 읽기 위치를 시작 부분으로 재설정
endservent: 데이터 베이스를 닫음
struct serven{
char *s_name;
char **s_aliases;
int s_port;
char *s_proto;
};
: 포트명을 인자로 받아 데이터베이스에서 해당 항목을 검색해 servent 구조체에 저장하고 그 주소를 리턴
#include <netdb.h>
struct servnet *getservbyname(const char *name, const chat *proto);
name: 검색할 포트명
proto: "tcp" 또는 "udp"
: 포트 번호를 인자로 받아 데이터베이스에서 해당 항목을 검색해 servent 구조체에 저장하고 그 주소를 리턴
#include <netdb.h>
struct servent *getservbyport(int port, const char *proto);
port: 검색할 포트 번호
proto: "tcp" 또는 "udp"