Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
3
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_PACKET_SIZE 1024

// Structure to represent a packet
typedef struct {
    char sourceIp[16];
    char destIp[16];
    char data[MAX_PACKET_SIZE];
} Packet;

// Function to send a packet
void sendPacket(Packet* packet) {
    printf("Sending packet...\n");
    printf("Source IP: %s\n", packet->sourceIp);
    printf("Destination IP: %s\n", packet->destIp);
    printf("Data: %s\n", packet->data);
    printf("Packet sent successfully!\n");
}

int main() {
    Packet packet;
    
    // Get the source and destination IP addresses from the user
    printf("Enter source IP address: ");
    fgets(packet.sourceIp, sizeof(packet.sourceIp), stdin);
    packet.sourceIp[strcspn(packet.sourceIp, "\n")] = '\0';

    printf("Enter destination IP address: ");
    fgets(packet.destIp, sizeof(packet.destIp), stdin);
    packet.destIp[strcspn(packet.destIp, "\n")] = '\0';

    // Get the data to be sent in the packet from the user
    printf("Enter data to send: ");
    fgets(packet.data, sizeof(packet.data), stdin);
    packet.data[strcspn(packet.data, "\n")] = '\0';

    // Send the packet
    sendPacket(&packet);

    return 0;
}