Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
frainz
pixelflut-c
Commits
359b2960
Commit
359b2960
authored
Nov 09, 2021
by
Paul Michel
Browse files
refactor
parent
072e9db1
Changes
3
Hide whitespace changes
Inline
Side-by-side
main.c
View file @
359b2960
...
...
@@ -7,7 +7,7 @@ int main(void)
{
printf
(
"This is supposed to become a pixelflut client in C.
\n
"
);
int
retval
=
pixelflut
(
"127.0.0.1"
,
1337
);
int
retval
=
pixelflut
(
"127.0.0.1"
,
1337
,
"singlepixel.px"
);
if
(
retval
)
{
printf
(
"Something went wronk
\n
"
);
...
...
pixelflut.c
View file @
359b2960
...
...
@@ -8,15 +8,14 @@
#include <stdio.h>
#include <stdlib.h>
#define MAXRCVLEN
50
0
#define MAXRCVLEN
3
0
int
pixelflut
(
char
*
dest_str
,
int
port
)
{
int
connectToIpPort
(
char
*
ip_str
,
int
port
)
{
struct
sockaddr_in
dest
;
memset
(
&
dest
,
0
,
sizeof
(
dest
));
dest
.
sin_family
=
AF_INET
;
inet_aton
(
dest
_str
,
&
dest
.
sin_addr
);
inet_aton
(
ip
_str
,
&
dest
.
sin_addr
);
dest
.
sin_port
=
htons
(
port
);
int
mysocket
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
...
...
@@ -27,21 +26,45 @@ int pixelflut(char* dest_str, int port)
return
-
1
;
}
size_t
sentsize
=
send
(
mysocket
,
"SIZE
\n
"
,
5
,
0
);
return
mysocket
;
}
int
getCanvasSize
(
int
socket
,
int
*
width
,
int
*
height
)
{
size_t
sentsize
=
send
(
socket
,
"SIZE
\n
"
,
5
,
0
);
if
(
sentsize
<
0
)
{
return
sentsize
;
}
char
recvbuffer
[
MAXRCVLEN
+
1
];
int
recvlen
=
recv
(
mysocket
,
recvbuffer
,
MAXRCVLEN
,
0
);
int
recvlen
=
recv
(
socket
,
recvbuffer
,
MAXRCVLEN
,
0
);
if
(
recvlen
<
0
)
{
return
recvlen
;
}
recvbuffer
[
recvlen
]
=
'\0'
;
// parse "SIZE <width> <height>"
// get pointers to the beginning of numbers and put these into atoi
char
*
widthPointer
=
strchr
(
recvbuffer
,
' '
)
+
1
;
// the char after the space is the beginning of the number
int
canvasW
idth
=
atoi
(
widthPointer
);
*
w
idth
=
atoi
(
widthPointer
);
char
*
heightPointer
=
strchr
(
widthPointer
,
' '
)
+
1
;
int
canvasHeight
=
atoi
(
heightPointer
);
printf
(
"Canvas size is %i x %i
\n
."
,
canvasWidth
,
canvasHeight
);
*
height
=
atoi
(
heightPointer
);
return
0
;
}
int
pixelflut
(
char
*
dest_str
,
int
port
,
char
*
sentfile
)
{
int
mysocket
=
connectToIpPort
(
dest_str
,
port
);
if
(
mysocket
<
0
)
{
return
mysocket
;
}
int
canvasWidth
,
canvasHeight
;
if
(
getCanvasSize
(
mysocket
,
&
canvasWidth
,
&
canvasHeight
)
<
0
)
{
return
-
1
;
}
printf
(
"Canvas size is %i x %i.
\n
"
,
canvasWidth
,
canvasHeight
);
return
0
;
}
\ No newline at end of file
pixelflut.h
View file @
359b2960
int
pixelflut
(
char
*
dest_str
,
int
port
);
\ No newline at end of file
int
pixelflut
(
char
*
dest_str
,
int
port
,
char
*
sentfile
);
\ No newline at end of file
Write
Preview
Supports
Markdown
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