本文整理汇总了C++中Inet_pton函数的典型用法代码示例。如果您正苦于以下问题:C++ Inet_pton函数的具体用法?C++ Inet_pton怎么用?C++ Inet_pton使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Inet_pton函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: creat_client
void creat_client()
{
int fd;
struct sockaddr_in cliddr,servddr;
char *ip = "127.0.0.1";
char buf[1000] = {0};
cliddr.sin_family = AF_INET;
Inet_pton(AF_INET,ip,&cliddr.sin_addr);
//随机端口
cliddr.sin_port = htons(0);
fd = Socket(AF_INET,SOCK_STREAM,0);
//Bind(fd,(struct sockaddr *)&cliddr,sizeof(cliddr));
servddr.sin_family = AF_INET;
Inet_pton(AF_INET,g_data.server.ip,&servddr.sin_addr);
servddr.sin_port = htons(g_data.server.port);
Connect(fd,(struct sockaddr *)&servddr,sizeof(servddr));
while(fgets(buf,DATA_MAX_LEN,stdin) != NULL)
{
buf[strlen(buf) -1] = 0;//不带回车
Send(fd,buf,strlen(buf),0);
int n =Recv(fd,buf,sizeof(buf),0);
buf[n] = 0;
printf("from server:%s\n",buf);
}
Close(fd);
}
开发者ID:jy02414216,项目名称:acf,代码行数:33,代码来源:acf_client.cpp
示例2: Inet_pton
void *thread_send_query(void *arg)
{
int fd;
struct sockaddr_in cliddr,servddr;
char *ip = "127.0.0.1";
char buf[1000] = {0};
cliddr.sin_family = AF_INET;
Inet_pton(AF_INET,ip,&cliddr.sin_addr);
//随机端口
cliddr.sin_port = htons(0);
fd = Socket(AF_INET,SOCK_STREAM,0);
//Bind(fd,(struct sockaddr *)&cliddr,sizeof(cliddr));
servddr.sin_family = AF_INET;
Inet_pton(AF_INET,g_data.server.ip,&servddr.sin_addr);
servddr.sin_port = htons(g_data.server.port);
Connect(fd,(struct sockaddr *)&servddr,sizeof(servddr));
for (int i = 0; i < g_data.per_thread_loop_num; ++i)
{
snprintf(buf, sizeof(buf), "%s", "hello, huangben!");
Send(fd,buf,strlen(buf),0);
int n =Recv(fd,buf,sizeof(buf),0);
buf[n] = 0;
printf("from server:%s\n",buf);
}
Close(fd);
return NULL;
}
开发者ID:jy02414216,项目名称:acf,代码行数:33,代码来源:acf_client.cpp
示例3: find_peer
int find_peer(int sockfd)
{
struct sockaddr_in servaddr;
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(CHAT_PORT);
/* Remove the last octet from the address */
char *dot = strrchr(subnet_address, '.');
dot[1] = 0;
int i = start_idx;
char try_address[strlen(subnet_address) + 4];
do {
snprintf(try_address, sizeof(try_address), "%s%d", subnet_address, i);
printf("Trying %s\n", try_address);
++i;
Inet_pton(AF_INET, try_address, &servaddr.sin_addr);
} while (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0);
printf("Bound!\n");
return -1;
}
开发者ID:emdeha,项目名称:peer-to-peer,代码行数:25,代码来源:lan_chat-v2.c
示例4: main
int
main(int argc, char **argv)
{
int sock_fd;
struct sockaddr_in servaddr;
int echo_to_all=0;
if(argc < 2)
err_quit("Missing host argument - use '%s host [echo]'\n",
argv[0]);
if(argc > 2) {
printf("Echoing messages to all streams\n");
echo_to_all = 1;
}
sock_fd = Socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
// 下面這一個是多餘的,沒有效果
// servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
SctpTurnOnAllEvent(sock_fd);
if(echo_to_all == 0)
sctpstr_cli(stdin,sock_fd,(SA *)&servaddr,sizeof(servaddr));
else
sctpstr_cli_echoall(stdin,sock_fd,(SA *)&servaddr,sizeof(servaddr));
Close(sock_fd);
return(0);
}
开发者ID:nightfly19,项目名称:renyang-learn,代码行数:31,代码来源:client.c
示例5: main
int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
int pdes[2];
char recvline[MAXLINE + 1];
int n;
if (argc != 3)
err_quit("usage: echocli01 <IPaddress> <write PIPE descriptor> \n\r");
pdes[1] = *argv[2];
n = write(pdes[1] , "Time Client\n", 12);
if( n < 0) printf("\n\r Time_Client: Error in writing to pipe");
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(8888);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) ;
write(pdes[1] , "Connection to server established\n ", 32);
while ( (n = Read(sockfd, recvline, MAXLINE)) > 0) {
recvline[n] = 0; /* null terminate */
Fputs(recvline, stdout);
}
exit(0);
}
开发者ID:jayagodugu,项目名称:Projects,代码行数:34,代码来源:time_cli.c
示例6: main
int
main(int argc, char **argv)
{
int sock_fd;
struct sockaddr_in servaddr;
struct sctp_event_subscribe evnts;
if(argc != 2)
err_quit("Missing host argument - use '%s host'\n",
argv[0]);
sock_fd = Socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
/* include mod_client04 */
bzero(&evnts, sizeof(evnts));
evnts.sctp_data_io_event = 1;
evnts.sctp_association_event = 1;
Setsockopt(sock_fd,IPPROTO_SCTP, SCTP_EVENTS,
&evnts, sizeof(evnts));
sctpstr_cli(stdin,sock_fd,(SA *)&servaddr,sizeof(servaddr));
/* end mod_client04 */
close(sock_fd);
return(0);
}
开发者ID:AnSwErYWJ,项目名称:UNP,代码行数:28,代码来源:sctpclient04.c
示例7: main
int main(int argc, char **argv)
{
char *spfd=argv[2];
int pfd=atoi(spfd);
Writen(pfd,"Child is Running.\n",strlen("Child is running.\n"));
printf("Time -- %s\n\n", argv[1]);
int sockfd;
struct sockaddr_in servaddr;
sockfd=Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_port=htons(TIME_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
int connstatus=connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
if(connstatus==-1)
{
Writen(pfd,"Server is Closed!\n",strlen("Server is Closed!\n"));
return 1;
}
str_clib(stdin, sockfd, pfd);
exit(0);
}
开发者ID:finallyjustice,项目名称:netprog,代码行数:32,代码来源:time_cli.c
示例8: main
int
main(int argc, char **argv)
{
int i, sockfd[5];
struct sockaddr_in servaddr;
if(argc != 2)
err_quit("usage: tcpcli <IPaddress>");
for(i = 0; i< 5; i++) {
sockfd[i] = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Connect(sockfd[i], (SA *)&servaddr, sizeof(servaddr));
}
str_cli(stdin, sockfd[0]);
exit(0);
}
开发者ID:Ectheow,项目名称:UNP,代码行数:25,代码来源:echocli_multi.c
示例9: main
int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: tcpcli <IPaddress>");
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(13); /* daytime server */
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Signal(SIGPIPE, sig_pipe);
Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
sleep(2);
Write(sockfd, "hello", 5);
sleep(2);
Write(sockfd, "world", 5);
exit(0);
}
开发者ID:337240552,项目名称:linux-programming,代码行数:27,代码来源:tsigpipe.c
示例10: main
int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: udpcli <IPaddress>");
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
sockfd = Socket(AF_INET, SOCK_DGRAM, 0);
bzero(&cliaddr, sizeof(cliaddr));
cliaddr.sin_family = AF_INET;
cliaddr.sin_addr.s_addr = htonl(INADDR_ANY);
cliaddr.sin_port = htons(0); /* force assignment of ephemeral port */
Bind(sockfd, (SA *) &cliaddr, sizeof(cliaddr));
dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr));
exit(0);
}
开发者ID:rkks,项目名称:refer,代码行数:26,代码来源:udpcli05.c
示例11: main
int main(int argc,char *argv[]){
int cli_parent_fd = strtol(argv[2],NULL,10);
int sockfd,confd;
int port_num = 5590;
char feedback[MAXLINE];
struct sockaddr_in servaddr;
//Create a TCP socket that will connect to the port of time server.
sockfd = Socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(port_num);
Inet_pton(AF_INET,argv[1],&servaddr.sin_addr);
//Connect to the server using the socket just created.
confd = connect(sockfd,(SA*)&servaddr,sizeof(servaddr));
if(confd < 0){
//If connection with the server fails.
bzero(feedback,sizeof(feedback));
strcpy(feedback,"[Client][Time]Server could not be reached\n");
Write(cli_parent_fd,feedback,strlen(feedback));
close(cli_parent_fd);
exit(0);
}
time_server(cli_parent_fd,sockfd,port_num);
close(sockfd);
close(cli_parent_fd);
close(confd);
exit(0);
}
开发者ID:dethakur,项目名称:NetworkProgramming,代码行数:34,代码来源:time_cli.c
示例12: main
int main(int argc, char** argv) {
struct rlimit limit;
getrlimit (RLIMIT_STACK, &limit);
printf ("\nStack Limit = %ld and %ld max\n", limit.rlim_cur, limit.rlim_max);
int sockfd;
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: tcpcli <IPaddress>");
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons( SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
str_cli( stdin, sockfd); /* do it all */
close( sockfd);
exit(0);
}
开发者ID:bharathvu,项目名称:unix_networking_projects,代码行数:28,代码来源:main.cpp
示例13: main
int main(int argc, char **argv)
{
int sockfd, n;
char recvline[MAXLINE+1];
struct sockaddr_in servaddr;
if(argc != 2)
{
err_quit("usage: a.out <IPaddress>");
}
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(13); /* daytime server */
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Connect(sockfd, (SA*)&servaddr, sizeof(servaddr));
while((n = read(sockfd, recvline, MAXLINE)) > 0)
{
recvline[n] = 0;
if(fputs(recvline, stdout) == EOF)
{
err_sys("fputs error");
}
}
if(n < 0)
{
err_sys("read error");
}
exit(0);
}
开发者ID:jiangxincode,项目名称:unp,代码行数:34,代码来源:daytimetcpcli.c
示例14: main
int
main(int argc, char **argv)
{
int sockfd;
socklen_t len;
struct sockaddr_in cliaddr, servaddr;
if (argc != 2)
err_quit("usage: udpcli <IPaddress>");
sockfd = Socket(AF_INET, SOCK_DGRAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
len = sizeof(cliaddr);
Getsockname(sockfd, (SA *) &cliaddr, &len);
printf("local address %s\n", Sock_ntop((SA *) &cliaddr, len));
exit(0);
}
开发者ID:elftech,项目名称:vmware-code,代码行数:25,代码来源:udpcli09.c
示例15: main
int main(int argc, char **argv)
{
int sockfd, n;
char recvline[MAXLINE+1];
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("Usage: cli <Ipaddress>");
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
// if (connect_nob(sockfd, (SA *)&servaddr, sizeof(servaddr)) < 0)
// err_sys("connect error");
connect_nob(sockfd, (SA *)&servaddr, sizeof(servaddr), 10);
while ((n = read(sockfd, recvline, MAXLINE)) > 0)
{
recvline[n] = 0;
if (fputs(recvline, stdout) == EOF)
err_sys("fputs error");
}
if (n < 0)
err_sys("read error");
exit(0);
}
开发者ID:crazy-canux,项目名称:cAPI,代码行数:31,代码来源:timecli.c
示例16: main
int main(int argc, char **argv)
{
int sockfd, rcvbuf, mss;
socklen_t len;
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: rcvbuf <IPaddrress>");
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
len = sizeof(rcvbuf);
Getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &len);
len = sizeof(mss);
Getsockopt(sockfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &len);
printf("defaults: SO_RCVBUF = %d, MSS = %d\n", rcvbuf, mss);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(13);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Connect(sockfd, (SA *)&servaddr, sizeof(servaddr));
len = sizeof(rcvbuf);
Getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &len);
len = sizeof(mss);
Getsockopt(sockfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &len);
printf("alter connect: SO_RCVBUF = %d, MSS = %d\n", rcvbuf, mss);
exit(0);
}
开发者ID:wuzhouhui,项目名称:unp,代码行数:31,代码来源:7.2.c
示例17: main
int main(int argc,char *argv[])
{
int listenfd,optval;
struct sockaddr_in servaddr;
if(argc != 2)
err_quit("usage:tcpsrvipv4 <IPAddress>");
listenfd = Socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(9999);
Inet_pton(AF_INET,argv[1],&servaddr.sin_addr);
optval = 1;
Setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));
Bind(listenfd,(SA *)&servaddr,sizeof(servaddr));
Listen(listenfd,LISTENQ);
pause();
}
开发者ID:lpswj,项目名称:UNP,代码行数:25,代码来源:tcpsrvipv4.c
示例18: sock_init
int sock_init(char *ip, int port, struct sockaddr_in *addr)
{
int sockfd = -1;
int optval = 1;
if ( port < 1024)
return NG;
bzero(addr, sizeof(struct sockaddr));
sockfd = x_socket(AF_INET, SOCK_DGRAM, 0);
addr->sin_family = AF_INET;
addr->sin_port = htons(port);
if (ip == NULL) {
addr->sin_addr.s_addr = htonl(INADDR_ANY);
x_bind(sockfd, (SA *)addr, sizeof(struct sockaddr));
printf("bind OK\n");
}
else {
Inet_pton(AF_INET, ip, &(addr->sin_addr));
x_connect(sockfd, (SA *)addr, sizeof(struct sockaddr));
}
x_setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int));
return sockfd;
}
开发者ID:caoaiming,项目名称:Improve-UDP,代码行数:28,代码来源:API.c
示例19: main
int
main(int argc, char **argv)
{
int sockfd;
void sig_alrm(int);
struct itimerval val;
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: tcpcli <IPaddress>");
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
/* Set interval timer to go off before 3WHS completes */
Signal(SIGALRM, sig_alrm);
val.it_interval.tv_sec = 0;
val.it_interval.tv_usec = 0;
val.it_value.tv_sec = 0;
val.it_value.tv_usec = 50000; /* 50 ms */
if (setitimer(ITIMER_REAL, &val, NULL) == -1)
err_sys("setitimer error");
Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
str_cli(stdin, sockfd); /* do it all */
exit(0);
}
开发者ID:337240552,项目名称:linux-programming,代码行数:33,代码来源:tcpcli07.c
示例20: main
int
main(int argc, char **argv)
{
int sockfd;
struct linger ling;
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: tcpcli <IPaddress>");
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
str_cli(stdin, sockfd); /* do it all */
ling.l_onoff = 1;
ling.l_linger = 0;
Setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
exit(0);
}
开发者ID:337240552,项目名称:linux-programming,代码行数:27,代码来源:tcpcli10.c
注:本文中的Inet_pton函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论