of the pipe to be opened in the messages.
Check whether strtol() succeeds.
Map DLT_ values to a WTAP_ENCAP_ value regardless of whether it comes
from linktype_name_to_val() or strtol().
Clean up indentation.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@27075
f5534014-38df-0310-8fa8-
9805f1628bb7
struct stat pipe_stat;
#else
char *pncopy, *pos;
struct stat pipe_stat;
#else
char *pncopy, *pos;
wchar_t *err_str;
HANDLE hPipe = NULL;
#endif
wchar_t *err_str;
HANDLE hPipe = NULL;
#endif
} else {
#ifndef _WIN32
if (ws_stat(pipe_name, &pipe_stat) < 0) {
} else {
#ifndef _WIN32
if (ws_stat(pipe_name, &pipe_stat) < 0) {
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "The capture session could not be initiated "
- "due to error on pipe: %s", strerror(errno));
+ fprintf(stderr, "rawshark: The pipe %s could not be checked: %s\n",
+ pipe_name, strerror(errno));
return -1;
}
if (! S_ISFIFO(pipe_stat.st_mode)) {
return -1;
}
if (! S_ISFIFO(pipe_stat.st_mode)) {
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "The capture session could not be initiated because\n"
- "\"%s\" is neither an interface nor a pipe", pipe_name);
+ fprintf(stderr, "rawshark: \"%s\" is neither an interface nor a pipe\n",
+ pipe_name);
}
return -1;
}
rfd = ws_open(pipe_name, O_RDONLY | O_NONBLOCK, 0000 /* no creation so don't matter */);
if (rfd == -1) {
}
return -1;
}
rfd = ws_open(pipe_name, O_RDONLY | O_NONBLOCK, 0000 /* no creation so don't matter */);
if (rfd == -1) {
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "The capture session could not be initiated "
- "due to error on pipe open: %s", strerror(errno));
+ fprintf(stderr, "rawshark: \"%s\" could not be opened: %s\n",
+ pipe_name, strerror(errno));
return -1;
}
#else /* _WIN32 */
return -1;
}
#else /* _WIN32 */
g_free(pncopy);
if (!pos) {
g_free(pncopy);
if (!pos) {
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "The capture session could not be initiated because\n"
- "\"%s\" is neither an interface nor a pipe", pipe_name);
+ fprintf(stderr, "rawshark: \"%s\" is neither an interface nor a pipe\n",
+ pipe_name);
if (hPipe != INVALID_HANDLE_VALUE)
break;
if (hPipe != INVALID_HANDLE_VALUE)
break;
- if (GetLastError() != ERROR_PIPE_BUSY) {
+ err = GetLastError();
+ if (err != ERROR_PIPE_BUSY) {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
- NULL, GetLastError(), 0, (LPTSTR) &err_str, 0, NULL);
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "The capture session on \"%s\" could not be initiated "
- "due to error on pipe open: pipe busy: %s (error %d)",
- pipe_name, utf_16to8(err_str), GetLastError());
+ NULL, err, 0, (LPTSTR) &err_str, 0, NULL);
+ fprintf(stderr, "rawshark: \"%s\" could not be opened: %s (error %d)\n",
+ pipe_name, utf_16to8(err_str), err);
LocalFree(err_str);
return -1;
}
if (!WaitNamedPipe(utf_8to16(pipe_name), 30 * 1000)) {
LocalFree(err_str);
return -1;
}
if (!WaitNamedPipe(utf_8to16(pipe_name), 30 * 1000)) {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
- NULL, GetLastError(), 0, (LPTSTR) &err_str, 0, NULL);
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "The capture session could not be initiated "
- "due to error on pipe open: %s (error %d)",
- utf_16to8(err_str), GetLastError());
+ NULL, err, 0, (LPTSTR) &err_str, 0, NULL);
+ fprintf(stderr, "rawshark: \"%s\" could not be waited for: %s (error %d)\n",
+ pipe_name, utf_16to8(err_str), err);
LocalFree(err_str);
return -1;
}
LocalFree(err_str);
return -1;
}
rfd = _open_osfhandle((long) hPipe, _O_RDONLY);
if (rfd == -1) {
rfd = _open_osfhandle((long) hPipe, _O_RDONLY);
if (rfd == -1) {
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
- "The capture session could not be initiated "
- "due to error on pipe open: %s", strerror(errno));
+ fprintf(stderr, "rawshark: \"%s\" could not be opened: %s\n",
+ pipe_name, strerror(errno));
return -1;
}
#endif /* _WIN32 */
return -1;
}
#endif /* _WIN32 */
static gboolean
set_link_type(const char *lt_arg) {
char *spec_ptr = strchr(lt_arg, ':');
static gboolean
set_link_type(const char *lt_arg) {
char *spec_ptr = strchr(lt_arg, ':');
dissector_handle_t dhandle;
GString *pref_str;
dissector_handle_t dhandle;
GString *pref_str;
if (strncmp(lt_arg, "encap:", strlen("encap:")) == 0) {
dlt_val = linktype_name_to_val(spec_ptr);
if (strncmp(lt_arg, "encap:", strlen("encap:")) == 0) {
dlt_val = linktype_name_to_val(spec_ptr);
- if (dlt_val >= 0) {
- encap = dlt_val;
- return TRUE;
- }
- dlt_val = strtol(spec_ptr, NULL, 10);
- if (errno != EINVAL && dlt_val >= 0) {
- encap = wtap_pcap_encap_to_wtap_encap(dlt_val);
- if (encap == WTAP_ENCAP_UNKNOWN) {
+ if (dlt_val == -1) {
+ errno = 0;
+ val = strtol(spec_ptr, &p, 10);
+ if (p == spec_ptr || *p != '\0' || errno != 0 || val > INT_MAX) {
+ dlt_val = (int)val;
+ }
+ encap = wtap_pcap_encap_to_wtap_encap(dlt_val);
+ if (encap == WTAP_ENCAP_UNKNOWN) {
+ return FALSE;
} else if (strncmp(lt_arg, "proto:", strlen("proto:")) == 0) {
dhandle = find_dissector(spec_ptr);
if (dhandle) {
} else if (strncmp(lt_arg, "proto:", strlen("proto:")) == 0) {
dhandle = find_dissector(spec_ptr);
if (dhandle) {
epan_cleanup();
exit(2);
}
epan_cleanup();
exit(2);
}