Thông tin

Tác giả Maxime Piraux
Hạn chót 28/02/2024 23:59:59
Giới hạn nộp bài Không có giới hạn

Đăng nhập

Sockets - Creating a socket

In this exercise, you have to create a IPv6 socket, then connect it to the given destination and send a message through the socket.

To create the socket, you have to use the socket() call and provide it with the correct parameters. Make sure to configure it for the IPv6 domain and set its type to support datagrams. Datagrams are simple unreliable messages abstractions.

Setting the socket destination is achieved using the connect() call.

Use the pointer to the destination address that is passed by argument to your function to send a message to the correct destination. The send() call allows sending a message through the socket. For this exercice, send()'s flags argument will not be used.

The message you have to send is the sequence of odd digits as network-ordered integers (int) in increasing order.

For each of the calls that you use, if one of them were to encounter an error, immediately return -1. All required C headers are already included.

Manpages of interest:


Creating a socket

Copy the function signature and fill in its body

int create_and_send_message(const struct sockaddr *dest_addr, socklen_t addrlen) {
    // TODO: Create a IPv6 socket supporting datagrams
    // TODO: Connect it to the destination
    // TODO: Send the required message (cfr. statement) through the socket
    return 0;
}