互联网应用 Lab

Lab 3

#include <unistd.h>
#include <stdio.h>

int main() {
    char *arg[] = {"/bin/ls", 0};

    /* fork, and exec within child process */
    if (fork() == 0) {
        printf("In child process:\n");
        execv(arg[0], arg);
        printf("I will never be called\n");
    }

    printf("Execution continues in parent process\n");

    return 0;
}

#include <unistd.h>
#include <stdio.h>

int main() {
    pid_t t;
    t = fork();
    printf("fork returned %d\n", t);

    return 0;
}
#include <unistd.h>
#include <stdio.h>

int main() {

    pid_t t;

    printf("Original program, pid = %d\n", getpid());

    t = fork();
    if (t == 0) {
        printf("In child process, pid = %d, ppid = %d\n", getpid(), getppid());
    } else {
        printf("In parent, pid = %d, for returned = %d\n", getpid(), t);
    }

    return 0;
}
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";
#define FILE_MODE 0644

int main(void) {
    int fd;
    if ((fd = creat("file.hole", FILE_MODE)) < 0) {
        printf("creat error\n");
        return 1;
    }
    if (write(fd, buf1, 10) != 10) {
        printf("buf1 write error\n");
        return 1;
    }
    /*offset now = 10*/
    if (lseek(fd, 40, SEEK_SET) == -1) {
        printf("lseek error\n");
        return 1;
    }
    /*offset now = 40*/
    if (write(fd, buf2, 10) != 10) {
        printf("buf2 write error\n");
        return 1;
    }
    /*offset now = 50*/

    return 0;
}
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(void) {
    char quit = '.';
    char buf[10];
    int fd;
    if ((fd = open("out.out", O_RDWR | O_CREAT)) == -1)
        printf("Error in opening\n");
    while (buf[0] != quit) {
        read(0, buf, 1);
        write(fd, buf, 1);
        write(1, buf, 1);
    }
    close(fd);

    return 0;
}
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void signalRoutine(int);

int main(void) {
    printf("signal processing demo program\n");
    while (1) {
        signal(SIGINT, signalRoutine);
    }
}

void signalRoutine(int dummy) {
    printf("Signal routine called[%d]\n", dummy);
    exit(0);
}

Lab 4

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main() {
    char buf[10];
    int fd1, fd2;

    if ((fd1 = open("test1", O_RDWR | O_APPEND)) == -1) {
        printf("Error in opening-1\n");
        return 1;
    }

    if ((fd2 = open("test2", O_RDONLY)) == -1) {
        printf("Error in opening-2\n");
        return 1;
    }

    while ((read(fd2, buf, 1)) != 0) {
        write(fd1, buf, 1);
    }

    close(fd1);
    close(fd2);

    return 0;
}
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main() {
    int fd1;
    off_t off;
    char s[50];

    if ((fd1 = open("test1", O_RDWR | O_APPEND)) == -1) {
        printf("Error in opening-1\n");
        return 1;
    }

    write(fd1, "Hiiii", 5);
    off = lseek(fd1, 0, SEEK_SET);
    printf("Using append, offset: %lli\n", (long long) off);

//  off = lseek(fd1, -502, SEEK_CUR);
//  printf("%lli\n", (long long)off);

    read(fd1, s, 50);
    printf("String: %s\n", s);
    lseek(fd1, 0, SEEK_SET);
    write(fd1, "Abbbb", 5);

    close(fd1);

    return 0;
}

Lab 5

#include <stdio.h>
#include <netdb.h>
#include <arpa/inet.h>

int main(int argc, char *argv[]) {
    struct hostent *h;
    long addr;

    if (argc != 2) {
        printf("Usage:\n%s sample.com\nor\n%s 8.8.8.8\n", argv[0], argv[0]);
        return 1;
    }

    if (inet_addr(argv[1]) != -1) {
        addr = inet_addr(argv[1]);
        if ((h = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) == NULL) {
            printf("gethostbyaddr error for address: %s\n", argv[1]);
            return 1;
        }
    } else {
        if ((h = gethostbyname(argv[1])) == NULL) {
            printf("gethostbyname error for name: %s\n", argv[1]);
            return 1;
        }
    }

    printf("Looking information for host: %s\n", argv[1]);
    printf("Official Name: %s\n", h->h_name);

    while ((h->h_aliases)[0])
        printf("Host aliases: %s\n", *h->h_aliases++);
    while ((h->h_addr_list)[0])
        printf("IP address: %s\n", inet_ntoa(*(struct in_addr *) *h->h_addr_list++));

    return 0;
}

Lab 6

#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), sendto() and recvfrom() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */

#define ECHOMAX 255 /* Longest string to echo */

int main(int argc, char *argv[]) {
    int sock; /* Socket descriptor */
    struct sockaddr_in echoServAddr; /* Echo server address */
//  struct sockaddr_in fromAddr; /* Source address of echo */
    unsigned short echoServPort; /* Echo server port */
//  unsigned int fromSize; /* In-out of address size for recvfrom() */
    char *servIP; /* IP address of server */
    char *echoString; /* String to send to echo server */
//  char echoBuffer[ECHOMAX + 1]; /* Buffer for receiving echoed string */
    size_t echoStringLen; /* Length of string to echo */
//  int respStringLen; /* Length of received response */

    if (argc < 3) { /* Test for correct number of arguments */
        printf("Usage: %s <Server IP> <Echo Word>\n", argv[0]);
        exit(1);
    }

    servIP = argv[1]; /* First arg: server IP address (dotted quad) */
    echoServPort = 56325;

    /* Create a datagram/UDP socket */
    if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
        printf("socket() failed.\n");
    /* Construct the server address structure */
    memset(&echoServAddr, 0, sizeof(echoServAddr));/*Zero out structure*/
    echoServAddr.sin_family = AF_INET; /* Internet addr family */
    echoServAddr.sin_addr.s_addr = inet_addr(servIP);/*Server IP address*/
    echoServAddr.sin_port = htons(echoServPort); /* Server port */

    for (int i = 2; i < argc; i++) {
        echoString = argv[i]; /* Second arg: string to echo */
        if ((echoStringLen = strlen(echoString)) > ECHOMAX) /* Check input length */
            printf("Echo word too long.\n");
        /* Send the string to the server */
        if (sendto(sock, echoString, echoStringLen, 0, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) != echoStringLen)
            printf("sendto() sent a different number of bytes than expected.\n");
        printf("sending data to '%s'\n", servIP);
    }

//  /* Recv a response */
//  fromSize = sizeof(fromAddr);
//  if ((respStringLen = recvfrom(sock, echoBuffer, ECHOMAX, 0, (struct sockaddr *) &fromAddr, &fromSize)) != echoStringLen)
//      printf("recvfrom() failed\n");
//
//  if (echoServAddr.sin_addr.s_addr != fromAddr.sin_addr.s_addr) {
//      printf("Error: received a packet from unknown source.\n");
//      exit(1);
//  }
//  /* null-terminate the received data */
//  echoBuffer[respStringLen] = '\0';
//  printf("Received: %s\n", echoBuffer);/*Print the echoed message*/
    close(sock);

    return 0;
}
#include <stdio.h> /* for printf() and fprintf() */
//#include <sys/socket.h> /* for socket(), bind(), sendto() and recvfrom() */
#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */
//#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
//#include <unistd.h> /* for close() */

#define ECHOMAX 255 /* Longest string to echo */

void main(int argc, char *argv[]) {
    int sock; /* Socket */
    struct sockaddr_in echoServAddr; /* Local address */
    struct sockaddr_in echoClntAddr; /* Client address */
    unsigned int cliAddrLen; /* Length of client address */
    char echoBuffer[ECHOMAX]; /* Buffer for echo string */
    unsigned short echoServPort; /* Server port */
    ssize_t recvMsgSize; /* Size of received message */

    echoServPort = 56325;
    /* Create socket for sending/receiving datagrams */
    if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
        printf("socket() failed.\n");
    /* Construct local address structure */
    memset(&echoServAddr, 0, sizeof(echoServAddr));
    echoServAddr.sin_family = AF_INET;
    echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    echoServAddr.sin_port = htons(echoServPort);
    /* Bind to the local address */
    if ((bind(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr))) < 0)
        printf("bind() failed.\n");

    for (;;) { /* Run forever */
        /* Set the size of the in-out parameter */
        cliAddrLen = sizeof(echoClntAddr);
        /* Block until receive message from a client */
        if ((recvMsgSize = recvfrom(sock, echoBuffer, ECHOMAX, 0, (struct sockaddr *) &echoClntAddr, &cliAddrLen)) < 0)
            printf("recvfrom() failed.\n");
        echoBuffer[recvMsgSize] = '\0';
        printf("from %s:UDP%d : %s\n", inet_ntoa(echoClntAddr.sin_addr), echoClntAddr.sin_port, echoBuffer);
//      /* Send received datagram back to the client */
//      if ((sendto(sock, echoBuffer, recvMsgSize, 0, (struct sockaddr *) &echoClntAddr, sizeof(echoClntAddr))) != recvMsgSize)
//          printf("sendto() sent a different number of bytes than expected.\n");
    }
}

Lab 7

#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), bind(), sendto() and recvfrom() */
#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#include <fcntl.h>

int main(int argc, char *argv[]) {
    if (argc != 3) {
        printf("Usage:\n%s <IP Address> <File Name>\n", argv[0]);
        return 1;
    }

    int serverSock;
    struct sockaddr_in serverAddr;
    char *fileName, buffer[100];

    if ((serverSock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        printf("socket() failed.\n");

    memset(&serverAddr, 0, sizeof(serverAddr));
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_addr.s_addr = inet_addr(argv[1]);
    serverAddr.sin_port = htons(1234);

    connect(serverSock, (struct sockaddr *) &serverAddr, sizeof(serverAddr));
    printf("Connecting to server:  %s\n", argv[1]);

    send(serverSock, argv[2], strlen(argv[2]), 0);

    fileName = argv[2];
    strcat(fileName, ".bak\0");
    int file = open(fileName, O_RDWR | O_CREAT);
    int transferSize = 0, recvLen;
    while ((recvLen = recv(serverSock, buffer, 50, 0)) != 0) {
        write(file, buffer, recvLen);
        transferSize += recvLen;
    }
    close(file);
    printf("File received\n");
    printf("%d BYTES received, and stored in %s\n", transferSize, fileName);

    return 0;
}
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), bind(), sendto() and recvfrom() */
#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#include <fcntl.h>

void main(int argc, char *argv[]) {
    int serverSock, clientSock;
    struct sockaddr_in serverAddr, clientAddr;
    socklen_t clientAddrSize = sizeof(clientAddr);
    char fileName[20], buffer[100];

    if ((serverSock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        printf("socket() failed.\n");

    memset(&serverAddr, 0, sizeof(serverAddr));
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    serverAddr.sin_port = htons(1234);

    if ((bind(serverSock, (struct sockaddr *) &serverAddr, sizeof(serverAddr))) < 0)
        printf("bind() failed.\n");

    listen(serverSock, SOMAXCONN);

    while (1) {
        clientSock = accept(serverSock, (struct sockaddr *) &clientAddr, &clientAddrSize);
        printf("*********************************\n");
        printf("Accept client %s on TCP Port %d\n", inet_ntoa(clientAddr.sin_addr), clientAddr.sin_port);
        if (recv(clientSock, fileName, 20, 0)) {
            fileName[strlen(fileName)] = '\0';
            printf("This client request for file name: %s\n", fileName);
            int file = open(fileName, O_RDONLY);
            printf("Entering file transfer...\n");
            int transferSize = 0, sendLen;
            while ((sendLen = read(file, buffer, 50)) != 0){
                send(clientSock, buffer, sendLen, 0);
                transferSize += sendLen;
            }
            printf("End of the file\n");
            printf("%d BYTES data have been sent\n", transferSize);
            close(file);
        }
        close(clientSock);
    }
}

Lab 8

The Configuration of Wireshark

Capture the interface “enp2s0” which is my Ethernet adapter.
The filter rule is “udp port 67” for capturing DHCP packets, “udp port 53” for capturing DNS packets.

DHCP Message Format

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     op (1)    |   htype (1)   |   hlen (1)    |   hops (1)    |
+---------------+---------------+---------------+---------------+
|                            xid (4)                            |
+-------------------------------+-------------------------------+
|           secs (2)            |           flags (2)           |
+-------------------------------+-------------------------------+
|                          ciaddr  (4)                          |
+---------------------------------------------------------------+
|                          yiaddr  (4)                          |
+---------------------------------------------------------------+
|                          siaddr  (4)                          |
+---------------------------------------------------------------+
|                          giaddr  (4)                          |
+---------------------------------------------------------------+
|                                                               |
|                          chaddr  (16)                         |
|                                                               |
|                                                               |
+---------------------------------------------------------------+
|                                                               |
|                          sname   (64)                         |
+---------------------------------------------------------------+
|                                                               |
|                          file    (128)                        |
+---------------------------------------------------------------+
|                                                               |
|                          options (variable)                   |
+---------------------------------------------------------------+

DHCP

DHCP

Explanation

  • Message Type: 1 = BOOTREQUEST, 2 = BOOTREPLY
  • Hardware type: Hardware address type, see ARP section in “Assigned Numbers” RFC; e.g., ‘1’ = 10mb ethernet.
  • Hardware address length: Hardware address length (e.g. ‘6’ for 10mb ethernet).
  • Hops: Client sets to zero, optionally used by relay agents when booting via a relay agent.
  • Transaction ID: A random number chosen by the client, used by the client and server to associate messages and responses between a client and a server.
  • Seconds elapsed: Filled in by client, seconds elapsed since client began address acquisition or renewal process.
  • Bootp flags: Flags.
  • Client IP address: Only filled in if client is in BOUND, RENEW or REBINDING state and can respond to ARP requests.
  • Your (client) IP address: ‘your’ (client) IP address.
  • Next server IP address: IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK by server.
  • Relay agent IP address: Relay agent IP address, used in booting via a relay agent.
  • Client MAC address: Client hardware address.
  • Server host name: Optional server host name, null terminated string.
  • Boot file name: Boot file name, null terminated string; “generic” name or null in DHCPDISCOVER, fully qualifiedcdirectory-path name in DHCPOFFER.
  • Option: (1) Subnet Mask – The subnet mask option specifies the client’s subnet mask.
  • Option: (3) Router Option – The router option specifies a list of IP addresses for routers on the client’s subnet. Routers SHOULD be listed in order of preference.
  • Option: (6) Domain Name Server Option – The domain name server option specifies a list of Domain Name System name servers available to the client. Servers SHOULD be listed in order of preference.
  • Option: (12) Host Name Option – This option specifies the name of the client. The name may or may not be qualified with the local domain name.
  • Option: (15) Domain Name – This option specifies the domain name that client should use when resolving hostnames via the Domain Name System.
  • Option: (50) Requested IP Address – This option is used in a client request (DHCPDISCOVER) to allow the client to request that a particular IP address be assigned.
  • Option: (51) IP Address Lease Time – This option is used in a client request (DHCPDISCOVER or DHCPREQUEST) to allow the client to request a lease time for the IP address. In a server reply (DHCPOFFER), a DHCP server uses this option to specify the lease time it is willing to offer.
  • Option: (53) DHCP Message Type – This option is used to convey the type of the DHCP message. 1 = DHCPDISCOVER, 2 = DHCPOFFER, 3 = DHCPREQUEST, 5 = DHCPACK, 7 = DHCPRELEASE
  • Option: (54) Server Identifier – This option is used in DHCPOFFER and DHCPREQUEST messages, and may optionally be included in the DHCPACK and DHCPNAK messages. DHCP servers include this option in the DHCPOFFER in order to allow the client to distinguish between lease offers. DHCP clients use the contents of the ‘server identifier’ field as the destination address for any DHCP messages unicast to the DHCP server. DHCP clients also indicate which of several lease offers is being accepted by including this option in a DHCPREQUEST message. The identifier is the IP address of the selected server.
  • Option: (55) Parameter Request List – This option is used by a DHCP client to request values for specified configuration parameters. The list of requested parameters is specified as n octets, where each octet is a valid DHCP option code as defined in this document. The client MAY list the options in order of preference. The DHCP server is not required to return the options in the requested order, but MUST try to insert the requested options in the order requested by the client.
  • Option: (58) Renewal (T1) Time Value – This option specifies the time interval from address assignment until the client transitions to the RENEWING state.
  • Option: (59) Rebinding (T2) Time Value – This option specifies the time interval from address assignment until the client transitions to the REBINDING state.

  • By the packets I have captured, all of DHCP packets were sent by unicast.

Differences from lecture notes: your IP address is different because of the different DHCP server. No server IP address, no router IP address because the router in room is not DHCP server in BUPT campus.

Message Sequence Chart

Note over Client: Graceful shutdown
Client->Server: DHCPRELEASE
Note over Server: Discards lease
Note over Client: Begins initialization 
Client->Server: DHCPDISCOVER
Note over Server: Determines configuration
Server-->Client: DHCPOFFER
Note over Client: Collects replies
Client->Server: DHCPREQUEST
Note over Server: Commits configuration
Server-->Client: DHCPACK
Note over Client: Initialization complete

No.1 DHCP Release

@(Client to server relinquishing network address and cancelling remaining lease.)

Bootstrap Protocol (Release)
    Message type: Boot Request (1)
    Hops: 0
    Transaction ID: 0x6bb0247f
    Bootp flags: 0x0000 (Unicast)
        0... .... .... .... = Broadcast flag: Unicast
        .000 0000 0000 0000 = Reserved flags: 0x0000
    Client IP address: 10.205.0.212
    Your (client) IP address: 0.0.0.0
    Option: (53) DHCP Message Type (Release)
        Length: 1
        DHCP: Release (7)
    Option: (54) DHCP Server Identifier
        Length: 4
        DHCP Server Identifier: 10.3.9.3
    Option: (12) Host Name
        Length: 16
        Host Name: i.questionyu.com
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Hangzhou_56:f1:51 (00:23:89:56:f1:51)
  • IP address: Source: 10.205.0.212 Destination: 10.3.9.3
  • Port number: Source Port: 68 Destination Port: 67

No.2 DHCP Discover

@(Client broadcast to locate available servers.)

Bootstrap Protocol (Discover)
    Message type: Boot Request (1)
    Hops: 0
    Transaction ID: 0x7cf5b152
    Bootp flags: 0x0000 (Unicast)
        0... .... .... .... = Broadcast flag: Unicast
        .000 0000 0000 0000 = Reserved flags: 0x0000
    Client IP address: 0.0.0.0
    Your (client) IP address: 0.0.0.0
    Option: (53) DHCP Message Type (Discover)
        Length: 1
        DHCP: Discover (1)
    Option: (50) Requested IP Address
        Length: 4
        Requested IP Address: 10.205.0.212
    Option: (12) Host Name
        Length: 16
        Host Name: i.questionyu.com
    Option: (55) Parameter Request List
        Length: 13
        Parameter Request List Item: (1) Subnet Mask
        Parameter Request List Item: (28) Broadcast Address
        Parameter Request List Item: (2) Time Offset
        Parameter Request List Item: (3) Router
        Parameter Request List Item: (15) Domain Name
        Parameter Request List Item: (6) Domain Name Server
        Parameter Request List Item: (119) Domain Search
        Parameter Request List Item: (12) Host Name
        Parameter Request List Item: (44) NetBIOS over TCP/IP Name Server
        Parameter Request List Item: (47) NetBIOS over TCP/IP Scope
        Parameter Request List Item: (26) Interface MTU
        Parameter Request List Item: (121) Classless Static Route
        Parameter Request List Item: (42) Network Time Protocol Servers
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Broadcast (ff:ff:ff:ff:ff:ff)
  • IP address: Source: 0.0.0.0 Destination: 255.255.255.255
  • Port number: Source Port: 68 Destination Port: 67

No.3 DHCP Offer

@(Server to client in response to DHCPDISCOVER with offer of configuration parameters.)

Bootstrap Protocol (Offer)
    Message type: Boot Reply (2)
    Hops: 1
    Transaction ID: 0x7cf5b152
    Bootp flags: 0x0000 (Unicast)
        0... .... .... .... = Broadcast flag: Unicast
        .000 0000 0000 0000 = Reserved flags: 0x0000
    Client IP address: 0.0.0.0
    Your (client) IP address: 10.205.0.212
    Option: (53) DHCP Message Type (Offer)
        Length: 1
        DHCP: Offer (2)
    Option: (54) DHCP Server Identifier
        Length: 4
        DHCP Server Identifier: 10.3.9.3
    Option: (51) IP Address Lease Time
        Length: 4
        IP Address Lease Time: (3600s) 1 hour
    Option: (1) Subnet Mask
        Length: 4
        Subnet Mask: 255.255.255.224
    Option: (3) Router
        Length: 4
        Router: 10.205.0.193
    Option: (15) Domain Name
        Length: 11
        Domain Name: bupt.edu.cn
    Option: (6) Domain Name Server
        Length: 12
        Domain Name Server: 10.3.9.5
        Domain Name Server: 10.3.9.4
        Domain Name Server: 10.3.9.6
  • Frame address: Source: Hangzhou_56:f1:51 (00:23:89:56:f1:51) Destination: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f)
  • IP address: Source: 10.205.0.193 Destination: 10.205.0.212
  • Port number: Source Port: 67 Destination Port: 68

No.4 DHCP Request

@(Client message to servers either (a) requesting offered parameters from one server and implicitly declining offers from all others, (b) confirming correctness of previously allocated address after, e.g., system reboot, or (c) extending the lease on a particular network address.)

Bootstrap Protocol (Request)
    Message type: Boot Request (1)
    Hops: 0
    Transaction ID: 0x7cf5b152
    Bootp flags: 0x0000 (Unicast)
        0... .... .... .... = Broadcast flag: Unicast
        .000 0000 0000 0000 = Reserved flags: 0x0000
    Client IP address: 0.0.0.0
    Your (client) IP address: 0.0.0.0
    Option: (53) DHCP Message Type (Request)
        Length: 1
        DHCP: Request (3)
    Option: (54) DHCP Server Identifier
        Length: 4
        DHCP Server Identifier: 10.3.9.3
    Option: (50) Requested IP Address
        Length: 4
        Requested IP Address: 10.205.0.212
    Option: (12) Host Name
        Length: 16
        Host Name: i.questionyu.com
    Option: (55) Parameter Request List
        Length: 13
        Parameter Request List Item: (1) Subnet Mask
        Parameter Request List Item: (28) Broadcast Address
        Parameter Request List Item: (2) Time Offset
        Parameter Request List Item: (3) Router
        Parameter Request List Item: (15) Domain Name
        Parameter Request List Item: (6) Domain Name Server
        Parameter Request List Item: (119) Domain Search
        Parameter Request List Item: (12) Host Name
        Parameter Request List Item: (44) NetBIOS over TCP/IP Name Server
        Parameter Request List Item: (47) NetBIOS over TCP/IP Scope
        Parameter Request List Item: (26) Interface MTU
        Parameter Request List Item: (121) Classless Static Route
        Parameter Request List Item: (42) Network Time Protocol Servers
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Broadcast (ff:ff:ff:ff:ff:ff)
  • IP address: Source: 0.0.0.0 Destination: 255.255.255.255
  • Port number: Source Port: 68 Destination Port: 67

No.5 DHCP ACK

@(Server to client with configuration parameters, including committed network address.)

Bootstrap Protocol (ACK)
    Message type: Boot Reply (2)
    Hops: 1
    Transaction ID: 0x7cf5b152
    Bootp flags: 0x0000 (Unicast)
        0... .... .... .... = Broadcast flag: Unicast
        .000 0000 0000 0000 = Reserved flags: 0x0000
    Client IP address: 0.0.0.0
    Your (client) IP address: 10.205.0.212
    Option: (53) DHCP Message Type (ACK)
        Length: 1
        DHCP: ACK (5)
    Option: (54) DHCP Server Identifier
        Length: 4
        DHCP Server Identifier: 10.3.9.3
    Option: (51) IP Address Lease Time
        Length: 4
        IP Address Lease Time: (3600s) 1 hour
    Option: (1) Subnet Mask
        Length: 4
        Subnet Mask: 255.255.255.224
    Option: (3) Router
        Length: 4
        Router: 10.205.0.193
    Option: (15) Domain Name
        Length: 11
        Domain Name: bupt.edu.cn
    Option: (6) Domain Name Server
        Length: 12
        Domain Name Server: 10.3.9.5
        Domain Name Server: 10.3.9.4
        Domain Name Server: 10.3.9.6
  • Frame address: Source: Hangzhou_56:f1:51 (00:23:89:56:f1:51) Destination: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f)
  • IP address: Source: 10.205.0.193 Destination: 10.205.0.212
  • Port number: Source Port: 67 Destination Port: 68

DNS Message Format

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                      ID                       |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR|   Opcode  |AA|TC|RD|RA|   Z    |   RCODE   |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    QDCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    ANCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    NSCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                    ARCOUNT                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

DNS-A questionyu.com

DNS-A

No.1 DNS Query

Domain Name System (query)
    [Response In: 2]
    Transaction ID: 0x3a72
    Flags: 0x0100 Standard query
        0... .... .... .... = Response: Message is a query
        .000 0... .... .... = Opcode: Standard query (0)
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... .0.. .... = Z: reserved (0)
        .... .... ...0 .... = Non-authenticated data: Unacceptable
    Questions: 1
    Answer RRs: 0
    Authority RRs: 0
    Additional RRs: 0
    Queries
        questionyu.com: type A, class IN
            Name: questionyu.com
            [Name Length: 14]
            [Label Count: 2]
            Type: A (Host Address) (1)
            Class: IN (0x0001)
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Hangzhou_56:f1:51 (00:23:89:56:f1:51)
  • IP address: Source: 2001:da8:215:c506::beef Destination: 2001:4860:4860::8888
  • Port number: Source Port: 48542 Destination Port: 53

No.2 DNS Response

Domain Name System (response)
    [Request In: 1]
    [Time: 0.100708994 seconds]
    Transaction ID: 0x3a72
    Flags: 0x8180 Standard query response, No error
        1... .... .... .... = Response: Message is a response
        .000 0... .... .... = Opcode: Standard query (0)
        .... .0.. .... .... = Authoritative: Server is not an authority for domain
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... 1... .... = Recursion available: Server can do recursive queries
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 1
    Answer RRs: 2
    Authority RRs: 0
    Additional RRs: 0
    Queries
        questionyu.com: type A, class IN
            Name: questionyu.com
            [Name Length: 14]
            [Label Count: 2]
            Type: A (Host Address) (1)
            Class: IN (0x0001)
    Answers
        questionyu.com: type A, class IN, addr 104.31.77.20
            Name: questionyu.com
            Type: A (Host Address) (1)
            Class: IN (0x0001)
            Time to live: 299
            Data length: 4
            Address: 104.31.77.20
        questionyu.com: type A, class IN, addr 104.31.76.20
            Name: questionyu.com
            Type: A (Host Address) (1)
            Class: IN (0x0001)
            Time to live: 299
            Data length: 4
            Address: 104.31.76.20
  • Frame address: Source: Hangzhou_56:f1:51 (00:23:89:56:f1:51) Destination: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f)
  • IP address: Source: 2001:4860:4860::8888 Destination: 2001:da8:215:c506::beef
  • Port number: Source Port: 53 Destination Port: 48542

DNS-MX questionyu.com

DNS-MX

No.1 DNS Query

Domain Name System (query)
    [Response In: 2]
    Transaction ID: 0xfec1
    Flags: 0x0100 Standard query
        0... .... .... .... = Response: Message is a query
        .000 0... .... .... = Opcode: Standard query (0)
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... .0.. .... = Z: reserved (0)
        .... .... ...0 .... = Non-authenticated data: Unacceptable
    Questions: 1
    Answer RRs: 0
    Authority RRs: 0
    Additional RRs: 0
    Queries
        questionyu.com: type MX, class IN
            Name: questionyu.com
            [Name Length: 14]
            [Label Count: 2]
            Type: MX (Mail eXchange) (15)
            Class: IN (0x0001)
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Hangzhou_56:f1:51 (00:23:89:56:f1:51)
  • IP address: Source: 2001:da8:215:c506::beef Destination: 2001:4860:4860::8888
  • Port number: Source Port: 38337 Destination Port: 53

No.2 DNS Response

Domain Name System (response)
    [Request In: 1]
    [Time: 0.067065156 seconds]
    Transaction ID: 0xfec1
    Flags: 0x8180 Standard query response, No error
        1... .... .... .... = Response: Message is a response
        .000 0... .... .... = Opcode: Standard query (0)
        .... .0.. .... .... = Authoritative: Server is not an authority for domain
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... 1... .... = Recursion available: Server can do recursive queries
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 1
    Answer RRs: 1
    Authority RRs: 0
    Additional RRs: 0
    Queries
        questionyu.com: type MX, class IN
            Name: questionyu.com
            [Name Length: 14]
            [Label Count: 2]
            Type: MX (Mail eXchange) (15)
            Class: IN (0x0001)
    Answers
        questionyu.com: type MX, class IN, preference 10, mx mxdomain.qq.com
            Name: questionyu.com
            Type: MX (Mail eXchange) (15)
            Class: IN (0x0001)
            Time to live: 299
            Data length: 16
            Preference: 10
            Mail Exchange: mxdomain.qq.com
  • Frame address: Source: Hangzhou_56:f1:51 (00:23:89:56:f1:51) Destination: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f)
  • IP address: Source: 2001:4860:4860::8888 Destination: 2001:da8:215:c506::beef
  • Port number: Source Port: 53 Destination Port: 38337

DNS-PTR 8.8.8.8

DNS-PTR

No.1 DNS Query

Domain Name System (query)
    [Response In: 2]
    Transaction ID: 0x7806
    Flags: 0x0100 Standard query
        0... .... .... .... = Response: Message is a query
        .000 0... .... .... = Opcode: Standard query (0)
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... .0.. .... = Z: reserved (0)
        .... .... ...0 .... = Non-authenticated data: Unacceptable
    Questions: 1
    Answer RRs: 0
    Authority RRs: 0
    Additional RRs: 0
    Queries
        8.8.8.8.in-addr.arpa: type PTR, class IN
            Name: 8.8.8.8.in-addr.arpa
            [Name Length: 20]
            [Label Count: 6]
            Type: PTR (domain name PoinTeR) (12)
            Class: IN (0x0001)
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Hangzhou_56:f1:51 (00:23:89:56:f1:51)
  • IP address: Source: 2001:da8:215:c506::beef Destination: 2001:4860:4860::8888
  • Port number: Source Port: 33287 Destination Port: 53

No.2 DNS Response

Domain Name System (response)
    [Request In: 1]
    [Time: 0.055456438 seconds]
    Transaction ID: 0x7806
    Flags: 0x8180 Standard query response, No error
        1... .... .... .... = Response: Message is a response
        .000 0... .... .... = Opcode: Standard query (0)
        .... .0.. .... .... = Authoritative: Server is not an authority for domain
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... 1... .... = Recursion available: Server can do recursive queries
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 1
    Answer RRs: 1
    Authority RRs: 0
    Additional RRs: 0
    Queries
        8.8.8.8.in-addr.arpa: type PTR, class IN
            Name: 8.8.8.8.in-addr.arpa
            [Name Length: 20]
            [Label Count: 6]
            Type: PTR (domain name PoinTeR) (12)
            Class: IN (0x0001)
    Answers
        8.8.8.8.in-addr.arpa: type PTR, class IN, google-public-dns-a.google.com
            Name: 8.8.8.8.in-addr.arpa
            Type: PTR (domain name PoinTeR) (12)
            Class: IN (0x0001)
            Time to live: 86399
            Data length: 32
            Domain Name: google-public-dns-a.google.com
  • Frame address: Source: Hangzhou_56:f1:51 (00:23:89:56:f1:51) Destination: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f)
  • IP address: Source: 2001:4860:4860::8888 Destination: 2001:da8:215:c506::beef
  • Port number: Source Port: 53 Destination Port: 33287

DNS-AAAA questionyu.com

DNS-AAAA

No.1 DNS Query

Domain Name System (query)
    [Response In: 2]
    Transaction ID: 0x96a2
    Flags: 0x0100 Standard query
        0... .... .... .... = Response: Message is a query
        .000 0... .... .... = Opcode: Standard query (0)
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... .0.. .... = Z: reserved (0)
        .... .... ...0 .... = Non-authenticated data: Unacceptable
    Questions: 1
    Answer RRs: 0
    Authority RRs: 0
    Additional RRs: 0
    Queries
        questionyu.com: type AAAA, class IN
            Name: questionyu.com
            [Name Length: 14]
            [Label Count: 2]
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Hangzhou_56:f1:51 (00:23:89:56:f1:51)
  • IP address: Source: 2001:da8:215:c506::beef Destination: 2001:4860:4860::8888
  • Port number: Source Port: 52731 Destination Port: 53

No.2 DNS Response

Domain Name System (response)
    [Request In: 1]
    [Time: 0.068031471 seconds]
    Transaction ID: 0x96a2
    Flags: 0x8180 Standard query response, No error
        1... .... .... .... = Response: Message is a response
        .000 0... .... .... = Opcode: Standard query (0)
        .... .0.. .... .... = Authoritative: Server is not an authority for domain
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... 1... .... = Recursion available: Server can do recursive queries
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 1
    Answer RRs: 2
    Authority RRs: 0
    Additional RRs: 0
    Queries
        questionyu.com: type AAAA, class IN
            Name: questionyu.com
            [Name Length: 14]
            [Label Count: 2]
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
    Answers
        questionyu.com: type AAAA, class IN, addr 2400:cb00:2048:1::681f:4d14
            Name: questionyu.com
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
            Time to live: 299
            Data length: 16
            AAAA Address: 2400:cb00:2048:1::681f:4d14
        questionyu.com: type AAAA, class IN, addr 2400:cb00:2048:1::681f:4c14
            Name: questionyu.com
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
            Time to live: 299
            Data length: 16
            AAAA Address: 2400:cb00:2048:1::681f:4c14
  • Frame address: Source: Hangzhou_56:f1:51 (00:23:89:56:f1:51) Destination: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f)
  • IP address: Source: 2001:4860:4860::8888 Destination: 2001:da8:215:c506::beef
  • Port number: Source Port: 53 Destination Port: 52731

DNS-TXT google-public-dns-a.google.com

DNS-TXT

No.1 DNS Query

Domain Name System (query)
    [Response In: 2]
    Transaction ID: 0x8836
    Flags: 0x0100 Standard query
        0... .... .... .... = Response: Message is a query
        .000 0... .... .... = Opcode: Standard query (0)
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... .0.. .... = Z: reserved (0)
        .... .... ...0 .... = Non-authenticated data: Unacceptable
    Questions: 1
    Answer RRs: 0
    Authority RRs: 0
    Additional RRs: 0
    Queries
        google-public-dns-a.google.com: type TXT, class IN
            Name: google-public-dns-a.google.com
            [Name Length: 30]
            [Label Count: 3]
            Type: TXT (Text strings) (16)
            Class: IN (0x0001)
  • Frame address: Source: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f) Destination: Hangzhou_56:f1:51 (00:23:89:56:f1:51)
  • IP address: Source: 2001:da8:215:c506::beef Destination: 2001:4860:4860::8888
  • Port number: Source Port: 58105 Destination Port: 53

No.2 DNS Response

Domain Name System (response)
    [Request In: 1]
    [Time: 0.056486861 seconds]
    Transaction ID: 0x8836
    Flags: 0x8180 Standard query response, No error
        1... .... .... .... = Response: Message is a response
        .000 0... .... .... = Opcode: Standard query (0)
        .... .0.. .... .... = Authoritative: Server is not an authority for domain
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... 1... .... = Recursion available: Server can do recursive queries
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 1
    Answer RRs: 1
    Authority RRs: 0
    Additional RRs: 0
    Queries
        google-public-dns-a.google.com: type TXT, class IN
            Name: google-public-dns-a.google.com
            [Name Length: 30]
            [Label Count: 3]
            Type: TXT (Text strings) (16)
            Class: IN (0x0001)
    Answers
        google-public-dns-a.google.com: type TXT, class IN
            Name: google-public-dns-a.google.com
            Type: TXT (Text strings) (16)
            Class: IN (0x0001)
            Time to live: 86399
            Data length: 22
            TXT Length: 21
            TXT: http://xkcd.com/1361/
  • Frame address: Source: Hangzhou_56:f1:51 (00:23:89:56:f1:51) Destination: HewlettP_3c:7c:0f (e4:11:5b:3c:7c:0f)
  • IP address: Source: 2001:4860:4860::8888 Destination: 2001:da8:215:c506::beef
  • Port number: Source Port: 53 Destination Port: 52731

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注