Skip to content

Commit

Permalink
fix: style based on clang-tidy suggestions (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
3Hren authored Jan 14, 2025
1 parent 9826875 commit dcec762
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions sock-send/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ int sock_fd;

int done = 0;

struct __attribute__((__packed__)) packHeader {
struct __attribute__((__packed__)) pack_header {
uint32_t data_length;
};

static int
writeIovCount(int fd, struct iovec *iov, size_t count) {
write_iov_count(int fd, struct iovec *iov, size_t count) {
while (count > 0) {
ssize_t written = writev(fd, iov, count);
if (written < 0) {
Expand Down Expand Up @@ -66,10 +66,9 @@ write_thread(void *arg) {
const u_char *data;
static u_char zeros[8192];

uint64_t packetsCount = 0;
while (pcap_next_ex(pcap, &header, &data) >= 0 && !done) {

struct packHeader hdr;
struct pack_header hdr;
hdr.data_length = htonl(header->len);

struct iovec iov[3];
Expand All @@ -87,11 +86,9 @@ write_thread(void *arg) {
iov_count = 3;
}

if (writeIovCount(sock_fd, iov, iov_count) < 0) {
if (write_iov_count(sock_fd, iov, iov_count) < 0) {
break;
}

packetsCount++;
}

pcap_close(pcap);
Expand All @@ -103,7 +100,7 @@ write_thread(void *arg) {
}

int
readData(int fd, u_char *buf, ssize_t len) {
read_data(int fd, u_char *buf, ssize_t len) {
ssize_t ret = 0;
while (len > 0 && !done) {
ret = read(fd, buf, len);
Expand All @@ -128,9 +125,9 @@ readData(int fd, u_char *buf, ssize_t len) {
}

static int
readPacket(int fd, struct pcap_pkthdr *header, u_char *data) {
struct packHeader hdr;
if (readData(fd, (u_char *)&hdr, sizeof(hdr))) {
read_packet(int fd, struct pcap_pkthdr *header, u_char *data) {
struct pack_header hdr;
if (read_data(fd, (u_char *)&hdr, sizeof(hdr))) {
return -1;
}

Expand All @@ -140,7 +137,7 @@ readPacket(int fd, struct pcap_pkthdr *header, u_char *data) {
return -1;
}

if (readData(fd, data, hdr.data_length)) {
if (read_data(fd, data, hdr.data_length)) {
return -1;
}

Expand All @@ -157,14 +154,16 @@ read_thread(void *arg) {
struct pcap_dumper *dmp = pcap_dump_fopen(pcap, stdout);

u_char buffer[8192];
struct pcap_pkthdr tmp_pcap_packetHeader;
struct pcap_pkthdr tmp_pcap_packet_header;

for (; !done;) {
if (readPacket(sock_fd, &tmp_pcap_packetHeader, buffer)) {
if (read_packet(sock_fd, &tmp_pcap_packet_header, buffer)) {
break;
}

pcap_dump((unsigned char *)dmp, &tmp_pcap_packetHeader, buffer);
pcap_dump(
(unsigned char *)dmp, &tmp_pcap_packet_header, buffer
);
}

done = 1;
Expand Down

0 comments on commit dcec762

Please sign in to comment.