[問題]Ipv6的封包傳輸 In Ubunto

看板Linux作者 (charliejack)時間16年前 (2009/10/17 16:42), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
#include <errno.h> #include <error.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <netinet/in.h> #include <sys/socket.h> int main (int argc, char *argv[]) { int result = 0; struct addrinfo *ai; struct addrinfo hints; memset (&hints, '\0', sizeof(hints)); hints.ai_flags = AI_ADDRCONFIG; hints.ai_socktype = SOCK_STREAM; int e = getaddrinfo (argv[1], "echo", &hints, &ai); if(e != 0) error (EXIT_FAILURE, 0, "getaddrinfo: %s", gai_strerror (e)); struct addrinfo *runp = ai; while (runp !=NULL) { int sock = socket (runp->ai_family, runp->ai_socktype, runp->ai_protocol); if (sock != -1) { if(connect (sock, runp->ai_addr, runp->ai_addrlen) == 0) { char *line = NULL; size_t len = 0; ssize_t n = getline (&line, &len, stdin); write (sock, line, len); n = read (sock, line ,len); write (STDOUT_FILENO, line, n); close (sock); goto out; } close (sock); } runp = runp->ai_next; } error (0, 0, "cannot contact %s", argv[1]); result = 1; out: freeaddrinfo (ai); return result; } 這是我參考 http://people.redhat.com/drepper/userapi-ipv6.html 寫的 目前我是使用ubuntu 9.多版 我用過直接帶入參數 0 進 不過找不到位置 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.117.87.164
文章代碼(AID): #1AsOE78C (Linux)
文章代碼(AID): #1AsOE78C (Linux)