Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
udp sockets testing
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oleg Dzhimiev
udp sockets testing
Commits
d557dbcb
Commit
d557dbcb
authored
Mar 05, 2019
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
formatting
parent
ce5a85ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
69 deletions
+71
-69
sender.c
sender.c
+71
-69
No files found.
sender.c
View file @
d557dbcb
...
...
@@ -50,96 +50,98 @@ int generate_packet(char * buf, int pnum){
//client
int
main
(
int
argc
,
char
**
argv
)
{
struct
timeval
t0
;
int
fd
;
char
buffer
[
MAXLINE
];
int
res
=
0
;
struct
sockaddr_in
servaddr
;
in_addr_t
s_addr
=
INADDR_ANY
;
if
(
argc
>
1
){
if
(
!
inet_aton
(
argv
[
1
],
&
s_addr
)){
perror
(
"Invalid inet addr in argv[1]"
);
return
-
1
;
}
struct
timeval
t0
;
int
fd
;
char
buffer
[
MAXLINE
];
int
res
=
0
;
struct
sockaddr_in
servaddr
;
in_addr_t
s_addr
=
INADDR_ANY
;
if
(
argc
>
1
){
if
(
!
inet_aton
(
argv
[
1
],
&
s_addr
)){
perror
(
"Invalid inet addr in argv[1]"
);
return
-
1
;
}
}
if
(
(
fd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
{
perror
(
"socket creation failed"
);
exit
(
EXIT_FAILURE
);
}
if
(
(
fd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
{
perror
(
"socket creation failed"
);
exit
(
EXIT_FAILURE
);
}
memset
(
&
servaddr
,
0
,
sizeof
(
servaddr
));
memset
(
&
servaddr
,
0
,
sizeof
(
servaddr
));
// Server info
servaddr
.
sin_family
=
AF_INET
;
// IPv4
servaddr
.
sin_addr
.
s_addr
=
s_addr
;
servaddr
.
sin_port
=
htons
(
PORT
);
// Server info
servaddr
.
sin_family
=
AF_INET
;
// IPv4
servaddr
.
sin_addr
.
s_addr
=
s_addr
;
servaddr
.
sin_port
=
htons
(
PORT
);
struct
sockaddr_in
saddr
;
memset
(
&
saddr
,
0
,
sizeof
(
struct
sockaddr_in
));
saddr
.
sin_family
=
AF_INET
;
saddr
.
sin_port
=
htons
(
0
);
saddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
struct
sockaddr_in
saddr
;
memset
(
&
saddr
,
0
,
sizeof
(
struct
sockaddr_in
));
saddr
.
sin_family
=
AF_INET
;
saddr
.
sin_port
=
htons
(
0
);
saddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
saddr
,
sizeof
(
struct
sockaddr_in
))
<
0
){
printf
(
"BIND ERROR!"
);
}
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
saddr
,
sizeof
(
struct
sockaddr_in
))
<
0
){
printf
(
"BIND ERROR!"
);
}
printf
(
"Sending to %s:%d
\n
"
,
inet_ntoa
(
servaddr
.
sin_addr
),
PORT
);
printf
(
"Sending to %s:%d
\n
"
,
inet_ntoa
(
servaddr
.
sin_addr
),
PORT
);
int
frame_cnt
=
0
;
int
pnum
=
0
;
int
frame_cnt
=
0
;
int
pnum
=
0
;
if
(
connect
(
fd
,(
const
struct
sockaddr
*
)
&
servaddr
,
sizeof
(
servaddr
))
<
0
){
printf
(
"connect() error: %d"
,
errno
);
return
-
2
;
}
if
(
connect
(
fd
,(
const
struct
sockaddr
*
)
&
servaddr
,
sizeof
(
servaddr
))
<
0
){
printf
(
"connect() error: %d"
,
errno
);
return
-
2
;
}
// Send
while
(
true
){
// Send
while
(
true
){
random_string
(
buffer
,
MAXLINE
);
random_string
(
buffer
,
MAXLINE
);
for
(
int
i
=
0
;
i
<
NUMBER_OF_PACKETS_IN_FRAME
;
i
++
){
for
(
int
i
=
0
;
i
<
NUMBER_OF_PACKETS_IN_FRAME
;
i
++
){
gettimeofday
(
&
t0
,
NULL
);
printf
(
"packet: %06d, time: %lu.%06d
\n
"
,
pnum
,
t0
.
tv_sec
,
t0
.
tv_usec
);
gettimeofday
(
&
t0
,
NULL
);
printf
(
"packet: %06d, time: %lu.%06d
\n
"
,
pnum
,
t0
.
tv_sec
,
t0
.
tv_usec
);
generate_packet
(
buffer
,
pnum
);
// tested
//res = sendto(fd, (const char *)buffer, strlen(buffer), 0, (const struct sockaddr *) &servaddr, sizeof(servaddr));
// tested
//res = write(fd,(const char *)buffer,strlen(buffer));
generate_packet
(
buffer
,
pnum
);
//gettimeofday(&t0, NULL);
//printf("time before2 : %lu.%06d\n", t0.tv_sec,t0.tv_usec
);
// tested
//res = sendto(fd, (const char *)buffer, strlen(buffer), 0, (const struct sockaddr *) &servaddr, sizeof(servaddr)
);
int
iovcnt
;
struct
iovec
iov
[
3
]
;
// tested
//res = write(fd,(const char *)buffer,strlen(buffer))
;
char
*
buf1
=
"This is a longer string
\n
"
;
char
*
buf2
=
"This is the longest string in this example
\n
"
;
iov
[
0
].
iov_base
=
buffer
;
iov
[
0
].
iov_len
=
strlen
(
buffer
);
iov
[
1
].
iov_base
=
buf1
;
iov
[
1
].
iov_len
=
strlen
(
buf1
);
iov
[
2
].
iov_base
=
buf2
;
iov
[
2
].
iov_len
=
strlen
(
buf2
);
//gettimeofday(&t0, NULL);
//printf("time before2 : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
iovcnt
=
3
;
int
iovcnt
;
struct
iovec
iov
[
3
];
res
=
writev
(
fd
,
iov
,
iovcnt
);
char
*
buf1
=
"This is a longer string
\n
"
;
char
*
buf2
=
"This is the longest string in this example
\n
"
;
iov
[
0
].
iov_base
=
buffer
;
iov
[
0
].
iov_len
=
strlen
(
buffer
);
iov
[
1
].
iov_base
=
buf1
;
iov
[
1
].
iov_len
=
strlen
(
buf1
);
iov
[
2
].
iov_base
=
buf2
;
iov
[
2
].
iov_len
=
strlen
(
buf2
);
//gettimeofday(&t0, NULL);
//printf("time after : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
iovcnt
=
3
;
if
(
res
<
0
){
printf
(
" send result= %d, errno= %d
\n
"
,
res
,
errno
);
}
else
{
//printf(" sent %d bytes\n",res);
}
res
=
writev
(
fd
,
iov
,
iovcnt
);
//gettimeofday(&t0, NULL);
//printf("time after : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
if
(
res
<
0
){
printf
(
" send result= %d, errno= %d
\n
"
,
res
,
errno
);
}
else
{
//printf(" sent %d bytes\n",res);
}
pnum
++
;
}
//printf("%s\n",buffer);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment